#include"./ModuleA/stu.c"
#include"./ModuleB/cou.c"
struct Node* list=NULL;
struct Cou* list1=NULL; 
void menu(){
	printf("----------------[学生选课系统]-----------------\n");
	printf("\t\t0: 退出系统\n");
	printf("\t\t1: 插入学生\n");
	printf("\t\t2: 删除学生\n");
	printf("\t\t3: 修改学生\n");
	printf("\t\t4: 查询学生\n");
	printf("\t\t5: 浏览学生\n"); 
	printf("\t\t6: 插入课程\n");
	printf("\t\t7: 删除课程\n");
	printf("\t\t8: 修改课程\n");
	printf("\t\t9: 查询课程\n");
	printf("\t\t10: 浏览课程\n");
	printf("-----------------------------------------------\n");
	printf("请输入（0-10）:");
}
void keyDown(){
	int num;
	struct student tempData;
	struct course tempData1;
	scanf("%d",&num);
	switch(num)       //跳转系统
	{
		case 0:
			printf("\t\t0: 退出系统\n");
			system("pause");
			exit(0);
			break;
		case 1:
			printf("\t\t1: 插入学生\n");
			printf("请输入姓名,学号,已选课程,总计分数:");
			scanf("%s%s%s%s",tempData.name,tempData.num,tempData.lesson,tempData.score); 
			insertNodeByHead(list,tempData);
			saveInfoToFile("stu.txt",list);
			break;
		case 2:
			printf("\t\t2: 删除学生\n");
			printf("请输入要删除学生姓名:");
			scanf("%s",tempData.name);
			deleteNodeByAppoinName(list,tempData.name);
			saveInfoToFile("stu.txt",list);
			break;
		case 3:
			printf("\t\t3: 修改学生\n");
			printf("请输入修改学生的学号:");
			scanf("%s",tempData.num);
			if(searchNodeByAppoinNum(list,tempData.num)==NULL)
			{
				printf("未找到相关信息");
			}
			else
			{
				struct Node* curNode=searchNodeByAppoinNum(list,tempData.num);
				printf("请输入新的学生信息:姓名,学号,已选课程,总计分数:");
				scanf("%s%s%s%s",curNode->data.name,curNode->data.num,curNode->data.lesson,curNode->data.score); 
				saveInfoToFile("stu.txt",list);
			}
			break;
		case 4:
			printf("\t\t4: 查询学生\n");
			printf("请输入查找学生的学号:");
			scanf("%s",tempData.num);
			if(searchNodeByAppoinNum(list,tempData.num)==NULL)
			{
				printf("未找到相关信息");
			}
			else
			{
				printNode(searchNodeByAppoinNum(list,tempData.num));
			}
			break;
		case 5:
			printf("\t\t5: 浏览学生\n");
			printList(list);
			break;
		case 6:
			printf("\t\6: 插入课程\n");
			printf("请输入课程编号,课程名称,课程性质,授课学时,学分,课程已选人数,课程人数上限:");
			scanf("%s\t%s\t%s\t%s\t%s\t%s\t%s",tempData1.num,tempData1.name,tempData1.nature,tempData1.time,tempData1.score,tempData1.peo,tempData1.peom); 
			insertNodeByHead1(list1,tempData1);
			saveInfoToFile1("cou.txt",list1);
			break;
		case 7:
			printf("\t\t7: 删除课程\n");
			printf("请输入要删除课程名:");
			scanf("%s",tempData1.name);
			deleteNodeByAppoincName(list1,tempData1.name);
			saveInfoToFile1("cou.txt",list1);
			break;
		case 8:
			printf("\t\t8: 修改课程\n");
			printf("请输入修改课程的编号:");
			scanf("%s",tempData1.num);
			if(searchNodeByAppoincNum(list1,tempData1.num)==NULL)
			{
				printf("未找到相关信息");
			}
			else
			{
				struct Cou* curNode1=searchNodeByAppoincNum(list1,tempData1.num);
				printf("请输入新的课程信息:课程编号,课程名称,课程性质,授课学时,学分,课程已选人数,课程人数上限:");
				scanf("%s\t%s\t%s\t%s\t%s\t%s\t%s",curNode1->data.num,curNode1->data.name,curNode1->data.nature,curNode1->data.time,curNode1->data.score,curNode1->data.peo,curNode1->data.peom); 
				saveInfoToFile1("cou.txt",list1);
			}
			break;
		case 9:
			printf("\t\t9: 查询课程\n");
			printf("请输入查找课程的编号:");
			scanf("%s",tempData1.num);
			if(searchNodeByAppoincNum(list1,tempData1.num)==NULL)
			{
				printf("未找到相关信息");
			}
			else
			{
				printNode1(searchNodeByAppoincNum(list1,tempData1.num));
			}
			break;
		case 10:
			printf("\t\t10: 浏览课程\n");
			printList1(list1);
			break;
		default:
			printf("输入错误，重新输入\n ");
			
			break;			 
	}
}
int main(){
	list1=creatList1();
	list=creatList();
	readInfoFromFile2("cou.txt",list1);
	readInfoFromFile1("stu.txt",list);
	while(1)
	{
		menu();
		keyDown(); 
		system("pause"); 
	}
	return 0;
} 
